package cn.gzsxt.music.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gzsxt.music.query.SongListQueryObject;

@Mapper
public interface SongListMapper {

	@SelectProvider(method = "getAllSongListTotal", type = SongListProvider.class)
	Long selectSongListTotal(SongListQueryObject qo);

	@SelectProvider(method = "getAllSongList", type = SongListProvider.class)
	List<Map<String, Object>> selectSongList(SongListQueryObject qo);

	@SelectProvider(method = "selectLabelName", type = SongListProvider.class)
	List<Map<String, Object>> selectLabelName(String label);

	@InsertProvider(type = SongListProvider.class, method = "saveSongList")
	@Options(useGeneratedKeys = true, keyProperty = "songList_id", keyColumn = "songlist_id")
	int saveSongList(Map<String, Object> params);

	@Select("select  s.* , u.user_name , u.user_id from mc_songlist s , mc_user u where u.user_id = s.user_id and s.songList_id = #{songList_id}")
	List<Map<String, Object>> getUserBysongList_id(String songList_id);

	@SelectProvider(type = SongListProvider.class, method = "getLabelBysongList_id")
	List<Map<String, Object>> getLabelBysongList_id(String label);

	@Select("select r.song_id,r.song_name from mc_sslist a,mc_song r where a.song_id = r.song_id and a.songlist_id=#{songList_id};")
	List<Map<String, Object>> getSongBysongList_id(String songList_id);

	@Select("select * from mc_songlist where songList_id = #{songList_id}")
	List<Map<String, Object>> selectSongListById(String songList_id);

	@UpdateProvider(method = "updateSongList", type = SongListProvider.class)
	int updateSongList(Map<String, Object> params);

	@Delete("delete from mc_songlist where songList_id = #{songList_id}")
	int deleteSongListById(Long songList_id);

	@Select("select count(*) from mc_uslist where songList_id = #{songList_id}")
	Integer selectTotleLikeById(String songList_id);

	@Select("select avg(songList_id)from (select count(songList_id) songList_id from mc_uslist group by songList_id)temp")
	Integer getAvgLike();
}
